package me.yokeyword.sample.ui;
import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.view.View;

import me.yokeyword.fragmentation.anim.FragmentAnimator;
import me.yokeyword.sample.R;
/**
 * Created by YoKeyword on 16/2/3.
 */
public class BaseMainFragment extends BaseFragment{

    protected OnFragmentOpenDrawerListener mOpenDraweListener;

    protected void initToolbarNav(Toolbar toolbar){

        initToolbarNav(toolbar, false);
    }

    protected void initToolbarNav(Toolbar toolbar, boolean isHome){

        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
        toolbar.setNavigationOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v){
                if(mOpenDraweListener != null){

                    mOpenDraweListener.onOpenDrawer();
                }
            }
        });

        if(!isHome){

            initToolbarMenu(toolbar);
        }
    }
    @Override
    protected FragmentAnimator onCreateFragmentAnimation(){

        FragmentAnimator fragmentAnimator = _mActivity.getFragmentAnimator();
        fragmentAnimator.setEnter(0);
        fragmentAnimator.setExit(0);
        return fragmentAnimator;
    }
    @Override
    public void onAttach(Context context){

        super.onAttach(context);
        if(context instanceof OnFragmentOpenDrawerListener){

            mOpenDraweListener = (OnFragmentOpenDrawerListener) context;
        }else{

            throw new RuntimeException(context.toString()
                                        + " must implement OnFragmentOpenDrawerListener");
        }
    }
    @Override
    public void onDetach(){

        super.onDetach();
        mOpenDraweListener = null;
    }
    public interface OnFragmentOpenDrawerListener{

        void onOpenDrawer();
    }
}
